#include <bits/stdc++.h>
using namespace std;
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#define int long long
/*
    file freopen
*/
#define name "detect"
inline void file() {
    freopen(name ".in", "r", stdin);
    freopen(name ".out", "w", stdout);
}
/* quick read */
inline int read() {
    int x = 0, f = 1, ch;
    do ch = getchar();
    while (!isdigit(ch) && ch != '-');
    if (ch == '-') f = -1, ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
    return x * f;
}
/* quick write */
inline void write(int x) {
    stack<int> s;
    if (x < 0) putchar('-'), x = -x;
    do s.push(x % 10), x /= 10;
    while (x);
    while (!s.empty()) putchar(s.top() + '0'), s.pop();
}
/* quick read and write */

const int N = 1e5 + 20;
int a[N][3];
int d[N];
struct P {
    int l = 1, r = 0;
    friend bool operator<(P a, P b) {
        if (a.l == b.l) return a.r > b.r;
        return a.l < b.l;
    }
} c[N];
#define a0 2
#define v0 1
#define d0 0
//is the ith car's v over v
inline bool check(int x, int i, int v) {
    return a[i][v0] * a[i][v0] + 2 * a[i][a0] * x > v * v;
}

void solve(int n, int m) {
    int size = 0;
    sort(c + 1, c + size + 1);
    int count = 0;
    int minn = INT_MAX;
    for (int i = 1; i <= n; i++) {
        if (c[i].l > c[i].r) continue;
        minn = min(c[i].r, minn);
        if (c[i].l >= minn || minn >= c[i].r) {
            count++;
        }
        size++;
        cout << c[i].l << " " << c[i].r << endl;
    }
    write(size);
    putchar(' ');
    write(m - count);
    puts("");
}
//the x from the ith first to jth light
inline int xs(int j, int i) { return d[j] - a[i][0]; };
void MAIN() {
    int n = read(), m = read(), l = read(), v = read();
    for (int i = 1; i <= n; i++) {
        a[i][d0] = read();
        a[i][v0] = read();
        a[i][a0] = read();
    }
    for (int i = 1; i <= m; i++) {
        d[i] = read();
    }
    sort(d + 1, d + n + 1);
    for (int i = 1; i <= n; i++) {
        if (a[i][a0] > 0) {
            int s1 = xs(m, i);
            if (s1 >= 0 && check(s1, i, v)) {  //che zai ce su qian mo su du chao le
                int j = 1;
                for (; j <= m; j++) {
                    int s = xs(j, i);
                    if (s >= 0 && check(s, i, v)) {
                        break;
                    }
                }
                c[i] = {j, m};
            }
        } else if (a[i][a0] == 0) {
            if (a[i][v0] > v) {
                int j = 1;
                for (; j <= m; j++) {
                    int s = xs(j, i);
                    if (s >= 0) {
                        break;
                    }
                }
                c[i] = {j,
                        m};
            }
        } else {
            int s1 = xs(m, i);
            if (s1 >= 0 && a[i][v0] > v) {
                int j = 1;
                int t = 1;
                for (; j <= m; j++) {
                    int s = xs(j, i);
                    if (s < 0) t = j;
                    if (s >= 0 && !check(s, i, v)) {
                        break;
                    }
                }
                c[i] = {t + 1, j - 1};
            }
        }
    }
    /* for (int i = 1; i <= n; i++) {
        write(c[i].l);
        putchar(' ');
        write(c[i].r);
        puts("");
    } */
    solve(n, m);
}
signed main() {
    file();
    int T = read();
    while (T--) {
        MAIN();
    }
    return 0;
}